Imports System.Text
Imports IICBusinessLogic.PeriodProcessing
Imports org.model.lib
Imports IICBusinessLogic

<TestClass()>
Public Class TestDASPeriods

    <TestMethod()>
    Public Sub testDASLoadPasHistory()

        ModelContext.newForUnitTests()

        Dim maxPeriodDate As Date = _
            ModelContext.CurrentDBUtils.getDtValue("select MAX(PeriodDate) from Period where DiplomaSuperTypeId=5")

        Try
            ModelContext.beginTrans()

            Dim c As New CertifSatisfiedReqsProviderDAS
            Dim sStudent As Student = StudentDataUtils.findOne("membernumber={0}", 2819)
            Dim certType As CertificationType = CertificationTypeDataUtils.findByKey(8)
            Dim pPeriod As Period = PeriodDataUtils.findOne("DiplomaSuperTypeId=5 and periodcode=N'09Β'")

            Dim lst As List(Of CertificationSatisfiedRequirement) = c.getStudentCertificationSatisfiedRequirement(pPeriod, certType, sStudent)

            Assert.AreEqual(lst.Count, 4)

            sStudent = StudentDataUtils.findOne("membernumber={0}", 862)
            lst = c.getStudentCertificationSatisfiedRequirement(pPeriod, certType, sStudent)
            Assert.AreEqual(lst.Count, 4)

            'rollback so we do not save to the database
            ModelContext.rollbackTrans()
        Finally
            ModelContext.rollbackTrans()
        End Try
    End Sub

    <TestMethod()>
    Public Sub testDAS2819()
        ModelContext.newForUnitTests()

        Try
            ModelContext.beginTrans()
            Dim june09period As Period = PeriodDataUtils.findByKey(78) 'june 2009
            Dim jan10period As Period = PeriodDataUtils.findByKey(79) 'ΙΑΝΟΥΑΡΙΟΥ 2010
            Dim ceProcessor As New CreditsAndExamsProcessor(june09period)

            ceProcessor.addStudentToProcess(2819, 862, 4214, 1309)

            Dim procesor As New PeriodProcessor(june09period)
            procesor.ExamsStudentProcessor = ceProcessor
            procesor.processPeriodAndStoreToDb()

            procesor = New PeriodProcessor(jan10period)
            procesor.processPeriodAndStoreToDb()
            'rollback so we do not save to the database
            ModelContext.rollbackTrans()
        Finally
            ModelContext.rollbackTrans()
        End Try
    End Sub
End Class
